package top.tangyh.basic.spring_mvc.controller.system;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.tangyh.basic.spring_mvc.base.R;
import top.tangyh.basic.spring_mvc.database.mybatis.conditions.query.QueryWrap;
import top.tangyh.basic.spring_mvc.controller.base.SuperController;
import top.tangyh.basic.spring_mvc.entity.BasePosition;
import top.tangyh.basic.spring_mvc.request.PageParams;
import top.tangyh.basic.spring_mvc.service.system.BasePositionService;
import top.tangyh.basic.spring_mvc.vo.query.system.BasePositionPageQuery;
import top.tangyh.basic.spring_mvc.vo.result.system.BasePositionResultVO;
import top.tangyh.basic.spring_mvc.vo.save.system.BasePositionSaveVO;
import top.tangyh.basic.spring_mvc.vo.update.system.BasePositionUpdateVO;
/**
 * <p>
 * 前端控制器
 * 岗位
 * </p>
 *
 * @author CJ
 * @date 2021-10-18
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/basePosition")
public class BasePositionController extends SuperController<BasePositionService, Long, BasePosition, BasePositionSaveVO, BasePositionUpdateVO, BasePositionPageQuery, BasePositionResultVO> {

    @Override
    public QueryWrap<BasePosition> handlerWrapper(BasePosition model, PageParams<BasePositionPageQuery> params) {
        QueryWrap<BasePosition> wrap = super.handlerWrapper(model, params);
        wrap.lambda().in(BasePosition::getOrgId, params.getModel().getOrgIdList());
        return wrap;
    }

    //检测名称是否可用
    @GetMapping("/check")
    public R<Boolean> check(@RequestParam String name, @RequestParam Long orgId, @RequestParam(required = false) Long id) {
        return success(superService.check(name, orgId, id));
    }
}
